package com.bo.client.Controller;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.bo.Entity.Comment;
import com.bo.Service.ProductCommentService;

@Controller
public class ProductCommentController {
	
	
	@Autowired
	private ProductCommentService commentService;
	
	
	
	@RequestMapping(value="/product_comment.do",method=RequestMethod.POST)
	public ResponseEntity<String> saveComment(@RequestParam("rate") double rate
			                ,@RequestParam("content") String content
			                ,@RequestParam("productId") String productId){
		
		
		Date date=new Date();
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm");
		
		String time=sdf.format(date);
		
		commentService.save(new Comment(rate,content,time,productId));
		
		return new ResponseEntity<String>("success",new HttpHeaders(), HttpStatus.OK);
	}
	
	
	
	

}
